/*     */ package com.newcrm.businessarchives;
/*     */ 
/*     */ import com.newcrm.bean.CaptchaEntity;
/*     */ import com.newcrm.exception.CaptchaException;
/*     */ import com.newcrm.util.Util;
/*     */ import java.io.IOException;
/*     */ import java.io.UnsupportedEncodingException;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.Iterator;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import java.util.Set;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.jsoup.Connection;
/*     */ import org.jsoup.Connection.Response;
/*     */ import org.jsoup.Jsoup;
/*     */ import org.jsoup.nodes.Document;
/*     */ import org.jsoup.select.Elements;
/*     */ 
/*     */ public class GuangzhouSearchEngine extends SearchEngine
/*     */   implements CaptchaSearchEngine
/*     */ {
/*  32 */   private static Logger logger = Logger.getLogger(GuangzhouSearchEngine.class
/*  33 */     .getName());
/*     */   private static final String IMAGE_URL = "http://www.gzaic.gov.cn/GZCX/WebUI/Content/Handler/ValidateCode.ashx";
/*     */ 
/*     */   public GuangzhouSearchEngine()
/*     */   {
/*     */   }
/*     */ 
/*     */   public GuangzhouSearchEngine(String name)
/*     */   {
/*  42 */     this.name = standardizedName(name);
/*     */   }
/*     */ 
/*     */   protected Map<String, Object> getCompanyByWeb()
/*     */     throws CaptchaException
/*     */   {
/*  54 */     String url = null;
/*     */     try {
/*  56 */       url = "http://www.gzaic.gov.cn/GZCX/WebUI/Content/Handler/ZTHandler.ashx?0.5611273906859717&Cpager=1&HID=ZT&where=&qymc=" + 
/*  57 */         URLEncoder.encode(this.name.trim(), "utf-8") + 
/*  58 */         "&zch=&qylx=qy&bl=true&VC=" + this.captcha;
/*     */     } catch (UnsupportedEncodingException e1) {
/*  60 */       e1.printStackTrace();
/*     */     }
/*  62 */     if (url == null) {
/*  63 */       return null;
/*     */     }
/*  65 */     Connection connection = Jsoup.connect(url);
/*     */ 
/*  67 */     CaptchaEntityManager captchaEntityManager = 
/*  68 */       CaptchaEntityManager.getInstance();
/*  69 */     CaptchaEntity captchaEntity = captchaEntityManager.get(
/*  70 */       "gz", false);
/*  71 */     for (Map.Entry cookie : captchaEntity.cookies.entrySet()) {
/*  72 */       connection.cookie((String)cookie.getKey(), (String)cookie.getValue());
/*     */     }
/*     */ 
/*     */     try
/*     */     {
/*  79 */       Document doc = connection.userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)").timeout(10000)
/*  80 */         .get();
/*     */ 
/*  83 */       String id = getId(doc.select("body").text());
/*  84 */       if ((id == null) || (id.trim().length() == 0)) {
/*  85 */         return null;
/*     */       }
/*     */ 
/*  88 */       url = "http://www.gzaic.gov.cn/GZCX/WebUI/Content/Handler/ZTHandler.ashx?op=0.09497184123904129&_k=" + 
/*  89 */         id + "&type=true";
/*  90 */       Connection connection2 = Jsoup.connect(url);
/*     */ 
/*  92 */       Iterator localIterator2 = captchaEntity.cookies
/*  92 */         .entrySet().iterator();
/*     */ 
/*  91 */       while (localIterator2.hasNext()) {
/*  92 */         Map.Entry cookie = (Map.Entry)localIterator2.next();
/*  93 */         connection2.cookie((String)cookie.getKey(), (String)cookie.getValue());
/*     */       }
/*     */ 
/*  96 */       doc = connection2.userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)").timeout(10000).get();
/*     */ 
/*  99 */       return getDetail(doc.select("body").text());
/*     */     } catch (IOException e) {
/* 101 */       logger.warn("get guangzhou company info failed", e);
/*     */     }
/*     */ 
/* 104 */     return null;
/*     */   }
/*     */ 
/*     */   private Map<String, Object> getDetail(String body)
/*     */   {
/* 109 */     if ((body == null) || (body.trim().length() == 0)) {
/* 110 */       return null;
/*     */     }
/* 112 */     JSONObject json = JSONObject.fromObject(body);
/* 113 */     Map map = new HashMap();
/* 114 */     map.put("SN", (String)json.get("zch"));
/* 115 */     map.put("CompanyName", (String)json.get("qymc"));
/* 116 */     map.put("Address", (String)json.get("qyzz"));
/* 117 */     map.put("CompanyType", (String)json.get("qylx"));
/* 118 */     map.put("Header", (String)json.get("qyfr"));
/* 119 */     map.put("FoundedDate", (String)json.get("jyqxz"));
/* 120 */     map.put("RegisteredCapital", (String)json.get("zczb"));
/* 121 */     map.put("RegistrationAuthority", (String)json.get("djjg"));
/* 122 */     map.put("BusinessScope", (String)json.get("jyfw"));
/* 123 */     map.put("AnnualinSpectionResult", (String)json.get("qyzt"));
/* 124 */     map.put("UpdateDate", Util.date2Str(new Date()));
/* 125 */     if ((map.get("CompanyName") != null) && 
/* 126 */       (((String)map.get("CompanyName")).trim().length() > 0)) {
/* 127 */       super.saveDB(map);
/*     */     }
/*     */ 
/* 131 */     CaptchaEntity captchaEntity = CaptchaEntityManager.getInstance().get(
/* 132 */       "gz", false);
/* 133 */     captchaEntity.code = this.captcha;
/* 134 */     captchaEntity.createDate = new Date();
/*     */ 
/* 136 */     return map;
/*     */   }
/*     */ 
/*     */   private String getId(String body) throws CaptchaException
/*     */   {
/* 141 */     if ((body == null) || (body.trim().length() == 0)) {
/* 142 */       return null;
/*     */     }
/*     */ 
/* 145 */     if ("false".equals(body)) {
/* 146 */       throw new CaptchaException();
/*     */     }
/*     */ 
/* 149 */     if (!body.contains("all")) {
/* 150 */       return null;
/*     */     }
/* 152 */     String startKey = "'all':'";
/* 153 */     int start = body.indexOf(startKey);
/* 154 */     if (start <= 0) {
/* 155 */       return null;
/*     */     }
/*     */ 
/* 158 */     String sub = body.substring(start + startKey.length());
/*     */ 
/* 160 */     start = sub.indexOf("'");
/* 161 */     if (start <= 0) {
/* 162 */       return null;
/*     */     }
/*     */ 
/* 165 */     return sub.substring(0, start);
/*     */   }
/*     */ 
/*     */   public CaptchaEntity downloadImage()
/*     */   {
/* 177 */     Connection.Response resp = null;
/*     */     try {
/* 179 */       resp = Jsoup.connect("http://www.gzaic.gov.cn/GZCX/WebUI/Content/Handler/ValidateCode.ashx").userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)")
/* 180 */         .timeout(10000).execute();
/*     */     } catch (IOException e) {
/* 182 */       e.printStackTrace();
/*     */     }
/*     */ 
/* 185 */     if (resp == null) {
/* 186 */       return null;
/*     */     }
/* 188 */     CaptchaEntity captchaEntity = new CaptchaEntity();
/* 189 */     resp.contentType();
/* 190 */     captchaEntity.cookies = resp.cookies();
/* 191 */     captchaEntity.image = resp.bodyAsBytes();
/* 192 */     captchaEntity.createDate = new Date();
/* 193 */     captchaEntity.code = "";
/* 194 */     return captchaEntity;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.businessarchives.GuangzhouSearchEngine
 * JD-Core Version:    0.6.1
 */